package loads

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// FLOAD Load float from local variable
type FLOAD struct{ base.Index8Instruction }

func (fl *FLOAD) Execute(jFrame *rtda.JFrame) {
	_fload(jFrame, fl.Index)
}

type FLOAD_0 struct{ base.NoOperandsInstruction }

func (fl *FLOAD_0) Execute(jFrame *rtda.JFrame) {
	_fload(jFrame, 0)
}

type FLOAD_1 struct{ base.NoOperandsInstruction }

func (fl *FLOAD_1) Execute(jFrame *rtda.JFrame) {
	_fload(jFrame, 1)
}

type FLOAD_2 struct{ base.NoOperandsInstruction }

func (fl *FLOAD_2) Execute(jFrame *rtda.JFrame) {
	_fload(jFrame, 2)
}

type FLOAD_3 struct{ base.NoOperandsInstruction }

func (fl *FLOAD_3) Execute(jFrame *rtda.JFrame) {
	_fload(jFrame, 3)
}

func _fload(jFrame *rtda.JFrame, index uint) {
	val := jFrame.LocalVars().GetFloat(index)
	jFrame.OperandStack().PushFloat(val)
}
